package day04;

public class Bag<T> {
    int[] data = new int[5];
    int size = 0;

    Bag() {

    }


    public static void main(String[] args) {
        Bag bag = new Bag();
        for (int i = 0; i < 1000000; i++) {
            bag.add(i);
           // bag.show();
        }
    }

    void show() {
        for (int i = 0; i < size; i++) {
            System.out.print(data[i] + ",");
        }
        System.out.println();
    }

    void add(int x) {
        if (size == data.length) {//double space
            System.err.println("-----------------double space---------------");
            int[] buffer = new int[data.length << 1];
            System.arraycopy(data, 0, buffer, 0, data.length);
            data = buffer;

        }
        data[size++] = x;
    }

}
